import { Query } from '@/utils/Query.js'
import { ref } from 'vue'
import { Modal } from 'ant-design-vue'

export default function (map) {
  let service = { docName: 'smartRoad', layerId: 2 }
  const options = ref([
    {
      id: '事件类型',
      name: '事件类型',
    },
    {
      id: '事件等级',
      name: '事件等级',
    },
    {
      id: '发生地点',
      name: '发生地点',
    },
    {
      id: '处理状态',
      name: '处理状态',
    },
  ])
  let optionValue = ref('事件类型')

  function queryByBox({ geom, callback }) {
    Query.queryByGeom({ geom, service, callback })
  }
  function queryByAttr({ where, callback }) {
    Query.queryBySql({ where, service, callback })
  }
  function queryAll({ callback }) {
    Query.queryByLayer({ service, callback })
  }
  function changeStatus({ value, FID }) {
    Query.queryByFid({
      FID,
      service,
      callback: (e) => downChangeStatus(e, value),
    })
  }
  function downChangeStatus(e, value) {
    console.log(e)
    e.SFEleArray[0].AttValue[7] = value
    var editService = new Zondy.Service.EditDocFeature(
      service.docName,
      service.layerId,
      {
        ip: 'localhost',
        port: '6163', //访问IGServer的端口号，.net版为6163，Java版为8089
      }
    )
    editService.update(e, onPntSuccess)
  }
  function onPntSuccess(data) {
    if (data.succeed) {
      Modal.success({
        content: '操作成功！',
      })
    } else {
      Modal.error({
        content: '操作失败，请稍后重试!',
      })
    }
  }
  return {
    queryByBox,
    queryByAttr,
    queryAll,
    changeStatus,
    options,
    optionValue,
  }
}
